<?php

namespace Modules\Common\General\Notification\Sms;


use Modules\Common\Models\SmsVerify;


class SmsVerifier
{
    //有效时间，分钟
    protected static $validMinute = 5;

    //检查验证码是否有效
    public static function verify($mobile, $code, $tag)
    {

        if (config('app.debug') && $code == '8888') {
            return true;
        }

        $record = SmsVerify::where([
            ['mobile', '=', $mobile],
            ['code', '=', $code],
            ['code', '!=', 0],
            ['tag', '=', $tag],
            ['status', '=', 1],
            ['created_at', '>', date('Y-m-d H:i:s', strtotime(sprintf('-%s minute', self::$validMinute)))]
        ])->first();
        if ($record === null) {
            return false;
        }
        $record->status = 2;
        $record->save();
        return true;
    }

}